#!/bin/bash
if [[ ${#args[@]} -lt 3 ]]
then
  prepare_usage
fi

# Configuration
version=${args[2]}
load_configuration $version

# Add version file
echo $version > $export_dir/version.frt

# Run prepare script (if it exists)
prepare_script
if [ -f $prepare_script ]
then
  chmod 755 $prepare_script
  export_dir=$export_dir $prepare_script
fi

# Upload the project
echo
$lftp_command <<END_SCRIPT
  $ftp_config
  echo "Logging in to ftp://$ftp_username@$ftp_host"
  open $ftp_host
  user $ftp_username $ftp_password
  echo "Uploading \"$export_dir\" to \"$ftp_swap_dir\""
  mirror -R --delete-first $export_dir $ftp_swap_dir
  bye
END_SCRIPT

# Cleanup
echo
echo "Cleaning tmp files"
rm -rf $tmp_dir
exit 0

